import { Application } from './services/core/application.js'
import { getLogger } from './services/core/logger.js'

const app = new Application()

app.init()
  .then(() => {
    const logger = getLogger()
    logger.info('Main', '✅ ZitMapX Backend Started')
    logger.info('Main', '📊 Dashboard: http://localhost:8700/health')
  })
  .catch(err => {
    const logger = getLogger()
    if (logger) {
      logger.error('Main', '❌ Startup failed:', { error: err.message })
    } else {
      console.error('❌ Startup failed:', err)
    }
    process.exit(1)
  })

process.on('SIGTERM', async () => {
  const logger = getLogger()
  logger.info('Main', 'SIGTERM received, shutting down gracefully...')
  await app.stop()
  process.exit(0)
})

process.on('SIGINT', async () => {
  const logger = getLogger()
  logger.info('Main', 'SIGINT received, shutting down gracefully...')
  await app.stop()
  process.exit(0)
})